package com.study_online.controller;

import com.study_online.domain.*;
import com.study_online.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张天霸
 */
@RestController
@RequestMapping("/forum")
public class ForumController {

    @Autowired
    private ForumService forumService;

    /**
     * 发表帖子
     * @param forumFatherPost
     * @return
     */
    @RequestMapping("/publish")
    public ResultInfo publish(@RequestBody ForumFatherPost forumFatherPost){
        ResultInfo info = forumService.publish(forumFatherPost);
        return info;
    }

    /**
     * 查看帖子（分页，模糊查询）
     * @param pageNum
     * @param pageSize
     * @param forumFatherPost
     * @return
     */
    @RequestMapping("/selectForumFatherPostByCondition")
    public ResultInfo selectForumFatherPostByCondition(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                        @RequestParam(defaultValue = "10",required = false) Integer pageSize,
                                        @RequestBody ForumFatherPost forumFatherPost){
        ResultInfo info = forumService.selectForumFatherPostByCondition(pageNum,pageSize,forumFatherPost);
        return info;
    }

    /**
     * 收藏帖子
     * @param collectedId
     * @return
     */
    @RequestMapping("/collect")
    public ResultInfo collect(Integer collectedId){
        ResultInfo info = forumService.collect(collectedId);
        return info;
    }

    /**
     * 取消收藏
     * @param collectedId
     * @return
     */
    @RequestMapping("/cancelCollect")
    public ResultInfo cancelCollect(Integer collectedId){
        ResultInfo info = forumService.cancelCollect(collectedId);
        return info;
    }

    /**
     * 修改帖子
     * @param forumFatherPost
     * @return
     */
    @RequestMapping("/update")
    public ResultInfo update(@RequestBody ForumFatherPost forumFatherPost){
        ResultInfo info = forumService.update(forumFatherPost);
        return info;
    }

    /**
     * 发表回帖
     * @param forumChildPost
     * @return
     */
    @RequestMapping("/replyPost")
    public ResultInfo replyPost(@RequestBody ForumChildPost forumChildPost){
        ResultInfo info = forumService.replyPost(forumChildPost);
        return info;
    }

    /**
     * 查看回帖（分页）
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/selectForumChildPost")
    public ResultInfo selectForumChildPost(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                           @RequestParam(defaultValue = "10",required = false) Integer pageSize){
        ResultInfo info = forumService.selectForumChildPost(pageNum,pageSize);
        return info;
    }


    /**
     * 评论回帖
     * @param forumComments
     * @return
     */
    @RequestMapping("/comment")
    public ResultInfo comment(@RequestBody ForumComments forumComments){
        ResultInfo info = forumService.comment(forumComments);
        return info;
    }

    /**
     * 查看评论（分页）
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/selectComment")
    public ResultInfo selectComment(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                    @RequestParam(defaultValue = "10",required = false) Integer pageSize){
        ResultInfo info = forumService.selectComment(pageNum,pageSize);
        return info;
    }

    /**
     * 点赞
     * @param likeId
     * @param likeType
     * @return
     */
    @RequestMapping("/like")
    public ResultInfo like(Integer likeId, String likeType){
        ResultInfo info = forumService.like(likeId,likeType);
        return info;
    }

    /**
     * 取消点赞
     * @param likeId
     * @param likeType
     * @return
     */
    @RequestMapping("/cancel")
    public ResultInfo cancel(Integer likeId, String likeType){
        ResultInfo info = forumService.cancel(likeId, likeType);
        return info;
    }

    /**
     * 点踩
     * @param dislikeId
     * @param dislikeType
     * @return
     */
    @RequestMapping("/dislike")
    public ResultInfo dislike(Integer dislikeId, String dislikeType){
        ResultInfo info = forumService.dislike(dislikeId,dislikeType);
        return info;
    }

    /**
     * 取消点踩
     * @param dislikeId
     * @param dislikeType
     * @return
     */
    @RequestMapping("/cancelDislike")
    public ResultInfo cancelDislike(Integer dislikeId, String dislikeType){
        ResultInfo info = forumService.cancelDislike(dislikeId,dislikeType);
        return info;
    }

    /**
     * 回复评论
     * @param forumReply
     * @return
     */
    @RequestMapping("/reply")
    public ResultInfo reply(@RequestBody ForumReply forumReply){
        ResultInfo info = forumService.reply(forumReply);
        return info;
    }



    /**
     * 查看回复（分页）
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/selectReply")
    public ResultInfo selectReply(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                  @RequestParam(defaultValue = "10",required = false) Integer pageSize){
        ResultInfo info = forumService.selectReply(pageNum,pageSize);
        return info;
    }

    /**
     * 删除回复
     * @param replyId
     * @return
     */
    @RequestMapping("/deleteReply")
    public ResultInfo deleteReply(Integer replyId){
        ResultInfo info = forumService.deleteReply(replyId);
        return info;
    }

    /**
     * 删除帖子（包含删除所有连带回帖、评论、收藏、点赞、点踩）
     * @param fpId
     * @return
     */
    @RequestMapping("/deleteForum")
    public ResultInfo deleteForum(Integer fpId){
        return forumService.deleteForum(fpId);
    }

    @RequestMapping("/findAllForum")
    public ResultInfo findAllForum(Integer pageNum, Integer pageSize){
        ResultInfo findAllForum = forumService.findAllForum(pageNum,pageSize);
        return findAllForum;
    }

    @RequestMapping("/findForumByPostTypeId")
    public ResultInfo findVideoId(Integer postTypeId){
        System.out.println(postTypeId);
        ResultInfo ForumByPostTypeId = forumService.findForumByPostTypeId(postTypeId);
        return ForumByPostTypeId;
    }









}